package com.taotao.tools.validate.annotations;

import com.taotao.tools.validate.validator.NoRepeatValidator;

import javax.validation.Constraint;
import javax.validation.Payload;
import java.lang.annotation.Documented;
import java.lang.annotation.Inherited;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.RetentionPolicy.RUNTIME;


/**
 * 校验集合元素是否有重复的,默认调用集合元素的equals方法判重；也可以指定校验集合元素中某个属性
 *
 * @author youbeiwuhuan
 */
@Inherited
@Target({FIELD, METHOD, PARAMETER})
@Retention(RUNTIME)
@Constraint(validatedBy = {NoRepeatValidator.class})
@Repeatable(NoRepeat.List.class)
@Documented
public @interface NoRepeat {
    /**
     * 指定要判重的属性名称,不指定则调用集合元素的equals方法判重
     *
     * @return
     */
    String targetField() default "";

    /**
     * 用于提示语.没配message则提示语为：{tipName}存在重复数据
     *
     * @return
     */
    String tipName() default "";

    String message() default "";

    Class<?>[] groups() default {};

    Class<? extends Payload>[] payload() default {};


    @Inherited
    @Target({FIELD, METHOD, PARAMETER})
    @Retention(RUNTIME)
    @Documented
    @interface List {
        NoRepeat[] value();
    }

}
